<template>
  <div id="app" class="login_container">
    <!--logo-->
    <div class="baidu_logo"><img src="../assets/baidu_main_logo.png" alt="" /></div>
    <!--标题-->
    <div class="mod-new-reg-text">
      <h3>用科技</h3>
      <p>让复杂的世界更简单</p>
    </div>
    <!--帮助中心-->
    <div class="mod-new-reg-footer">
      <span class="mod-new-reg-help">
        <a class="mode-new-reg-help-text" href="#" target="_blank">帮助中心</a>
        <span class="mod-new-reg-line"></span>
        <a class="mod-new-reg-service" href=""></a>
      </span>
      <span class="mod-new-reg-copyright">2021&nbsp;©Baidu</span>
    </div>

    <!--表单-->
    <div class="mod-reg clearfix mod-reg- mod-new-reg-content ">
      <!--表单标题-->
      <div class="new-reg-guide-login">
        <h3>欢迎注册</h3>
        <p>
          已有帐号？
          <span id="login_btn">
            <a href="#/register"><router-link :to="{ name: 'Login' }">登录</router-link></a>
          </span>
        </p>
      </div>
      <div class="reg-content tang-pass-reg" id="reg_content">
        <form autocomplete="off" id="" class="new-reg-v5" method="POST" style="margin-top: 40px">
          <el-form :model="UserInfo" status-icon :rules="rules" ref="UserInfo" label-width="100px" class="demo-ruleForm">
            <el-form-item label="用户名" prop="idCard" style="margin-bottom: 30px">
              <el-tooltip class="item" effect="dark" content="设置后不可更改,中英文均可最长支持14个字符" placement="top">
              <el-input class="input" type="text" v-model="UserInfo.idCard" autocomplete="off" placeholder="请设置用户名" clearable></el-input>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="手机号" prop="phone" style="margin-bottom: 30px">
              <el-input class="input" type="text" v-model="UserInfo.phone" autocomplete="off" placeholder="可用于找回密码" clearable></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password" style="margin-bottom: 30px">
              <el-tooltip class="item" effect="dark" content="长度为8~14个字符,不允许带有空格汉字" placement="top">
              <el-input class="input" type="password" v-model="UserInfo.password" autocomplete="off" placeholder="请设置密码" clearable></el-input>
              </el-tooltip>
            </el-form-item>
            <el-form-item><el-button class="button" style="margin-left: -50px;" type="primary" @click="submitForm()">注&nbsp;&nbsp;册</el-button></el-form-item>
          </el-form>
        </form>
      </div>
    </div>
  </div>
</template>

<script>
import token from '../components/token.vue';
export default {
  name: 'Login',
  data() {
    var idCard = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入用户名'));
      }else if (value.length >= 14) {
        callback(new Error('用户名长度必须为8~14个字符'));
      }
    };

    var phone = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入电话号码'));
      } else if (value.length != 11) {
        callback(new Error('请输入正确的手机号码'));
      }
    };
    var password = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      }  else if(value.match( /^[\u4E00-\u9FA5]{1,}$/)){
        callback(new Error('不允许输入汉字'));
      }  else if(value.indexOf(" ") != -1){
        callback(new Error('不允许密码中含有空格'));
      }
      else if (value.length < 8 || value.length >= 14) {
        callback(new Error('密码长度必须为8~14个字符'));
      }
    };
    return {
      UserInfo: {
        idCard: '',
        phone: '',
        password: ''
      },
      rules: {
        idCard: [{ validator: idCard, trigger: 'blur' }],
        phone: [{ validator: phone, trigger: 'blur' }],
        password: [{ validator: password, trigger: 'blur' }]
      }
    };
  },
  methods: {
    resetForm() {
      this.UserInfo.idCard = '';
      this.UserInfo.password = '';
    },
    submitForm() {
      let _this = this;
      this.$axios.post('http://localhost:8087/user/setUser', this.UserInfo).then(function(res) {
        if (res.data != -1) {
          alert('注册成功');
          _this.$router.push({ name: 'Index', query: { id: res.data } });
          localStorage.setItem('id', res.data);
          token.type = 1;
        } else {
          alert('注册失败');
        }
      });
      this.resetForm();
    }
  }
};
</script>

<style scoped>
.login_container {
  position: fixed;

  background: url('../assets/reg_bg_min.jpg') no-repeat;
  background-size: cover;
}
.baidu_logo img {
  margin-top: 50px;
  margin-left: 70px;
  height: 38px;
  width: 124px;
}

.mod-new-reg-text {
  position: fixed;
  left: 195px;
  top: 314px;
  color: #fff;
}

div {
  display: block;
}

.mod-new-reg-text h3 {
  font-size: 54px;
  letter-spacing: 0;
  font-weight: 700;
}

.mod-new-reg-text p {
  font-size: 32px;
  letter-spacing: 3.81px;
  font-weight: 300;
}

/*帮助中心*/
.mod-new-reg-footer {
  position: fixed;
  left: 70px;
  bottom: 57px;
  font-size: 14px;
  color: #fff;
}

.mod-new-reg-footer .mod-new-reg-help .mode-new-reg-help-text {
  filter: alpha(opacity=80);
  opacity: 0.8;
}

.mod-new-reg-footer .mod-new-reg-help a {
  text-decoration: none;
  color: #fff;
  cursor: pointer;
}
a {
  text-decoration: underline;
  color: #00c;
}
a {
  text-decoration: none;
  color: #2b78e4;
}

a:-webkit-any-link {
  color: -webkit-link;
  cursor: pointer;
  text-decoration: underline;
}
.mod-new-reg-footer {
  position: fixed;
  left: 70px;
  bottom: 57px;
  font-size: 14px;
  color: #fff;
}
body {
  font-family: PingFang-SC-Regular, Helvetica, 'Microsoft Yahei', '微软雅黑';
}

.mod-new-reg-footer .mod-new-reg-help .mod-new-reg-line {
  display: inline-block;
  width: 2px;
  height: 12px;
  filter: alpha(opacity=78);
  opacity: 0.78;
  margin: 0 12px 0 13px;
  background: #fff;
  position: relative;
  top: 1px;
}

.mod-new-reg-footer {
  position: fixed;
  left: 70px;
  bottom: 57px;
  font-size: 14px;
  color: #fff;
}
.mod-new-reg-footer .mod-new-reg-help a {
  text-decoration: none;
  color: #fff;
  cursor: pointer;
}
.mod-new-reg-service {
  display: inline-block;
  width: 16px;
  height: 16px;
  background: url(../assets/service.png) no-repeat;
  background-size: 100%;
  position: relative;
  top: 3px;
}

.mod-new-reg-footer .mod-new-reg-copyright {
  filter: alpha(opacity=54);
  opacity: 0.54;
  font-size: 12px;
  color: #fff;
  display: inline-block;
  padding-left: 30px;
}
.mod-new-reg-footer {
  position: fixed;
  left: 70px;
  bottom: 57px;
  font-size: 14px;
  color: #fff;
}

/*form表单*/
.mod-new-reg-content {
  height: 554px;
}

.mod-new-reg-content {
  position: absolute;
  right: 139px;
  width: 480px;
  background: #fff;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  overflow: hidden;
}

.mod-new-reg-content .new-reg-guide-login {
  margin: 30px 0 0 39px;
}

.mod-new-reg-content .new-reg-guide-login h3 {
  font-size: 36px;
  color: #000;
  padding-bottom: 4px;
}

.mod-new-reg-content .new-reg-guide-login p {
  font-size: 14px;
  color: #9b9b9b;
}

.mod-new-reg-content .new-reg-guide-login p span {
  color: #2e58ff;
  cursor: pointer;
}

.input {
  height: 50px;
  width: 340px;
}
.button {
  border-radius: 30px;
  height: 50px;
  width: 400px;
}
</style>
